package com.crm.dao.saling;

import com.crm.pojo.Pay;
import com.crm.vo.PayClientContractUserInfoVOList;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

/**
 * Created by dr5hx on 2018/8/10
 */
public interface PayDao extends CrudRepository<Pay, Long> {
    /**
     * 显示所有的付款列表
     *
     * @return
     */
    @Query("from Pay  p where p.payIsDel='否'")
    public List<Pay> showPayList();

    /**
     * 删除付款
     *
     * @param payId
     */
    @Query("update Pay  p set p.payIsDel='是' where p.payId=?1")
    @Modifying
    public void deletePayByPayId(Long payId);

    @Query("select new com.crm.vo.PayClientContractUserInfoVOList(pay,userInfo,purchase) from Pay  pay, Userinfo  userInfo,Purchase purchase,PlaningPay planingPay where pay.fkPayPlaningPayId=planingPay.planingPayId and planingPay.fkPlaningPayPurchaseId=purchase.purid and pay.fkPayEmpno=userInfo.uId and pay.payIsDel='否'")
    public List<PayClientContractUserInfoVOList> getPayClientContractUserInfoVOList(Pageable pageable);

    @Query("select count(p) from Pay  p where p.payIsDel='否'")
    Long getPayListCount();
}
